﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Phoenix.Xna.Framework.Components.Compositors
{
    public abstract class Compositor : DrawableComponent, ICompositor, I2DComponent
    {
        public Compositor()
            : base()
        {
            Scale = new Vector2(1.0f, 1.0f);
            Color = Color.White;
        }

        public Compositor(string id)
            : base(id)
        {
            Scale = new Vector2(1.0f, 1.0f);
            Color = Color.White;
        }

        protected override void Dispose(bool disposing)
        {
            SpriteBatch.Dispose();
            base.Dispose(disposing);
        }

        #region ICompositor

        public Vector2 Origin { get; set; }
        public Color Color { get; set; }
        public SpriteEffects Effect { get; set; }
        public float LayerDepth { get; set; }
        public SpriteBatch SpriteBatch { get; set; }

        #endregion

        #region I2DComponent Members

        public Vector2 Position { get; set; }

        public Vector2 Scale { get; set; }

        public float Rotation { get; set; }

        public void SetPosition(float? x, float? y)
        {
            float xPos = (x == null) ? Position.X : x.Value;
            float yPos = (y == null) ? Position.Y : y.Value;
            Position = new Vector2(xPos, yPos);
        }

        #endregion
    }
}
